<script setup>
import { useRouter } from "vue-router";

//跳转路由
const router = useRouter();
const gotoNav = (path) => {
  router.push({ path: path });
};

//从父组件获取导航内容数据
const props = defineProps({
  menuData: {
    type: Object,
    required: true,
  },
});
</script>

<template>
  <div class="sideBar">
    <h3 class="title">{{ menuData.title }}</h3>
    <ul class="menuList">
      <li
        v-for="(menuItem, index) in menuData.children"
        :key="index"
        @click="gotoNav(menuData.path + menuItem.path)"
        :class="{ active: $route.path === menuData.path + menuItem.path }"
      >
        <i class="iconfont" :class="menuItem.icon"></i>
        <span>{{ menuItem.title }}</span>
      </li>
    </ul>
  </div>
</template>

<style scoped lang="less">
.sideBar {
  width: 250px;
  padding-top: 20px;
  min-height:500px;
  box-shadow: 0px 0px 10px #c3c0c0;
  // border-right:5px solid #57B0A7;
  background-color: #fafafa;
  .title {
    font-size: 23px;
    height: 50px;
    text-align: center;
    line-height: 50px;
    // background-color:#1e9ab5;
    // color:white;
    // color:#1e9ab5;
  }
}
.menuList {
  width: 100%;
  list-style: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  li {
    width: 90%;
    height: 50px;
    display: flex;
    align-items: center;
    margin: 7px 0px;
    border-radius: 10px;
    position: relative;
    .iconfont {
      color: #9fa6b7;
      font-size: 20px;
      margin-right: 10px;
      position: absolute;
      left: 40px;
    }
    span {
      position: absolute;
      left: 72px;
      font-weight: 600;
      font-size: 19px;
      font-family: "黑体";
    }
  }
}
li.active {
  background-color: #e5f5f4;
  .iconfont {
    color: #57b0a7;
  }
}
li:hover {
  background-color: #e5f5f4;
  .iconfont {
    color: #57b0a7;
  }
}
</style>